package org.jiamandan.com.strategy.listener;


import com.alibaba.fastjson.JSON;
import io.netty.channel.Channel;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jiamandan.com.constant.DXConstant;
import org.jiamandan.com.dto.DXBasicDto;
import org.jiamandan.com.strategy.IDXContextListener;
import org.springframework.stereotype.Service;


@Service(value = DXConstant.Service.CMD_008)
@AllArgsConstructor
@Slf4j
public class DX008BSListenerService implements IDXContextListener {


    @Override
    public void doExecute(DXBasicDto dxBasicDto, Channel ctx) throws Exception {
        log.info("接收嘉满电-DX读取BS协议通信参数(CMD=008)【"+dxBasicDto.getDeviceNo()+"】报文:" + JSON.toJSONString(dxBasicDto));
        String payload = dxBasicDto.getData();
        String data1 = String.valueOf(Integer.parseInt(payload.substring(0, 4),16));
        String data2 =  String.valueOf(Integer.parseInt(payload.substring(4, 8),16));
        String data3 = String.valueOf(Integer.parseInt(payload.substring(8, 10),16));
        log.info("接收嘉满电-DX指令(CMD=004)，设备号=【{}】心跳阀值={},超时重发时间={},超时重发次数={}",dxBasicDto.getDeviceNo(),data1,data2,data3);
    }
}
